﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CoolCode.Web.UI.Controls
{
    public class ProductEditTemplate : ITemplate
    {
        private DataControlRowType templateType;

        private string columnName;

        private string cId;

        public ProductEditTemplate(DataControlRowType type, string colname, string controlId)
        {
            templateType = type;
            columnName = colname;
            cId = controlId;
        }

        public void InstantiateIn(System.Web.UI.Control container)
        {
            switch (templateType)
            {
                case DataControlRowType.Header:
                    Literal myHeadLiteral = new Literal();
                    myHeadLiteral.ID = cId;
                    myHeadLiteral.Text = "<b>" + columnName + "</b>";
                    container.Controls.Add(myHeadLiteral);
                    break;
                case DataControlRowType.DataRow:
                    HyperLink editLink = new HyperLink { ID = "lnkEdit_" + cId, Text="编辑", NavigateUrl="CreateProduct.aspx?key=" };
                    container.Controls.Add(editLink);
                    LinkButton lb = new LinkButton { ID = cId , CommandName = "Delete" , Text="删除" };
                    container.Controls.Add(lb);
                    break;
                default:
                    break;
            }
        }


    }
}
